<include file="Public:header" />
<link type="text/css" href="__PUBLIC__/css/dynamic.css" rel="stylesheet" />
<div class="container">
	<!-- Docs nav ================================================== -->
	<div class="page-header">
		<h4>{:L('USER_INFO')}</h4>
	</div>
	<div class="row">
		<div class="span12">
			<include file="Public:alert" />
		</div>
		<div class="span12">
			<form class="form-horizontal" enctype="multipart/form-data" action="{:U('user/edit')}" method="post" >
				<input type="hidden" name="user_id" value="{$user.user_id}"/>
				<table class="table span7">
					<thead>
						<tr>
							<td>&nbsp;</td>
							<td><input name="submit" class="btn btn-primary" type="submit" value="{:L('SAVE')}"/> &nbsp;<input class="btn" type="button" onclick="javascript:history.go(-1)" value="{:L('CANCEL')}"/></td>
						</tr>
					</thead>
					<tfoot>
						<tr>
							<td>&nbsp;</td>
							<td><input name="submit" class="btn btn-primary" type="submit" value="{:L('SAVE')}"/> &nbsp;<input class="btn" type="button" onclick="javascript:history.go(-1)" value="{:L('CANCEL')}"/></td>
						</tr>
					</tfoot>
					<tbody>
						<tr>
							<th colspan="2">{:L('BASIC_INFO')}</th>
						</tr>
						<tr>
							<td class="tdleft">{:L('USER_LOGO')}</td>
							<td><if condition="$user['img'] neq ''"><img src="{$user.img}" class="thumbnail img"/></if>
							<input name="img" type="file"> {:L('SUGGEST_SIZE')}
							</td>
						<tr>
						<tr>
							<td class="tdleft">{:L('USER_NAME')}</td>
							<td><if condition="session('?admin')"><input type="text" name="name" value="{$user['user_name']}"><else />{$user.user_name}</if></td>
						</tr>
						<tr>
							<td class="tdleft">{:L('MODIFY_PASSWORD')}</td>
							<td><input class="text-input small-input" type="password" name="password" id="password" value=""/></td>
						</tr>
						<tr>
							<td class="tdleft">{:L('USER_CATEGORY')}</td>
							<td><if condition="session('?admin')"><select name="category_id" id="category_id"><volist name="categoryList" id="temp"><option value="{$temp.category_id}" <if condition="$temp.category_id eq $user['category_id']">selected = "selected"</if>>{$temp.name}</option></volist></select><else />{$user.category}</if></td>
						</tr>
						<tr>
							<td class="tdleft">{:L('ACCOUNT_STATUS')}</td>
							<td><if condition="session('?admin')">
								<select id="status" name="status">
									<volist name="statuslist" id="temp" >
										<option value="{$key}" <if condition="$key eq $user['status']">selected = "selected"</if>>{$temp}</option>
									</volist>
								</select><else />{$statuslist[$user['status']]}</if>
							</td>
						</tr>
						<if condition="session('?admin')">
							<tr>
								<td class="tdleft">{:L('DEPARTMENT')}&nbsp;<span style="color:red;">*</span></td>  
								<td>
									<select id="department" name="department_id" onchange="changeRoleContent()">
										<option value=""></option>
										<volist name="department_list" id="temp">
											<option value="{$temp.department_id}">{$temp.name}</option>
										</volist>
									</select>
								</td>
							</tr>
							<tr>
								<td class="tdleft">{:L('POSITION')}&nbsp;<span style="color:red;">*</span></td>  
								<td>
									<select id="role" name="position_id">
										<option value=""></option>
										<volist name="position_list" id="temp">
											<option value="{$temp.position_id}">{$temp.name}</option>
										</volist>
									</select>
									
								</td>
							</tr>
						<else />
							<input type="hidden" name="position_id" value="{$_SESSION['position_id']}"/>
							<tr>
								<td class="tdleft">{:L('DEPARTMENT')}&nbsp;<span style="color:red;">*</span></td>  
								<td>{$user.department_name}</td>
							</tr>
							<tr>
								<td class="tdleft">{:L('POSITION')}&nbsp;<span style="color:red;">*</span></td>  
								<td>{$user.role_name}</td>
							</tr>
						</if>
						<tr>
							<td class="tdleft">{:L('SEX')}</td>
							<td><input type="radio"  name="sex" value="1" <if condition="$user['sex'] eq 1">checked="checked"</if>/>{:L('MALE')} 
							<input type="radio"  name="sex" value="2" <if condition="$user['sex'] eq 2">checked="checked"</if>/>{:L('FEMALE')}</td>
						</tr>
						<tr>
							<td class="tdleft">{:L('EMAIL')}&nbsp;<span style="color:red;">*</span></td>
							<td><input class="text-input small-input" name="email" type="text" value="{$user.email}"></td>
						</tr>
						<tr>
							<td class="tdleft">{:L('TELPHONE')}&nbsp;<span style="color:red;">*</span></td>
							<td><input class="text-input small-input" name="telephone" type="text" value="{$user.telephone}"></td>
						</tr>
						<tr>
							<td class="tdleft">{:L('ADDRESS')}</td>
							<td><textarea name="address" >{$user.address}</textarea></td>
						</tr>
						<tr>
							<th colspan="2">{:L('ACCOUNT_BIND_INFO')}</th>
						</tr>
						<tr>
							<td class="tdleft">{:L('WECHAT_BIND')}</td>
							<td><if condition="$user[weixinid]">{:L('BOUND_WECHAT_ID')}{$user.weixinid}<else />{:L('not_bind')}<a href="javascript:void(0);" id="weixin">{:L('CLICK_SCAN_QR_COD')}</a></if></td>
						</tr>
					</tbody>
				</table>
			</form>			
		</div> <!-- End #tab1 -->		
	</div> <!-- End #main-content -->	
</div>
<div class="hide" id="dialog-weixin" title="{:L('SCAN_QR_COD')}">loading...</div>
<script type="text/javascript">
$("#dialog-weixin").dialog({
    autoOpen: false,
    modal: true,
	width: 600,
	Height: 600,
	position: ["center",100]
});
function changeRoleContent(){
	department_id = $('#department').val();
	if(department_id == ''){
		$("#role").html('');
	}else{
		$.ajax({
			type:'get',
			url:'index.php?m=user&a=getpositionlist&id='+department_id,
			async:false,
			success:function(data){
				options = '';
				if(data.data){
					$.each(data.data, function(k, v){
						options += '<option value="'+v.position_id+'">'+v.name+'</option>';
					});
				}
				$("#role").html(options);
			},
			dataType:'json'
		});		
	}
}
$('#role').click(
	function(){
		department_id = $('#department').val();
		if(department_id == ''){
			alert("{:L('SELECT_DEPARTMENT_FIRST')}");
		}
	}
);
$(function(){
	$("#weixin").click(function(){
		$('#dialog-weixin').dialog('open');
		$('#dialog-weixin').load('{:U("user/weixin")}');
	});
	
	$("#department option[value='{$user['department_id']}']").prop("selected", true);
	$("#role option[value='{$user['position_id']}']").prop("selected", true);
});
</script>
<include file="Public:footer" />	